package azalea.mqtt.message.utils;

public class ByteUtils {
	private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
	public static void copy(byte[] src,byte[] des,int srcStart,int desStart, int len) {
		for(int i=0;i<len;++i) {
			des[desStart+i]=src[srcStart+i];
		}
	}
	public static String bytesToHex(byte[] bytes, int length) {
		char[] hexChars = new char[length * 3];
		for (int i = 0; i < bytes.length && i < length; i++) {
			int v = bytes[i] & 0xFF; // 获取无符号字节值
			hexChars[i * 3] = HEX_CHARS[v >>> 4]; // 高4位
			hexChars[i * 3 + 1] = HEX_CHARS[v & 0x0F]; // 低4位
			hexChars[i * 3 + 2] = ' '; // 空格
		}
		return new String(hexChars,0,length);
	}
}
